<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物车</title>
    <link rel="stylesheet" href="css/globe.css"/>
    <link rel="stylesheet" href="css/cart.css"/>
    <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
    <script>
        $(function () {
            var userId = '<%=session.getAttribute("userId")%>';
            if (userId !== "null" && userId.length > 0) {
                localStorage.setItem("userId", userId);
                loadCart(userId);
            } else {
                alert("您还未登录，请登录");
                window.location.href = "${pageContext.request.contextPath}/login.jsp";
            }

            function loadCart(userId) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/cart/cartList",
                    type: "get",
                    dataType: "json",
                    data: {
                        userId: userId
                    },
                    success: function (data) {
                        if (data.flag) {
                            localStorage.setItem("list", JSON.stringify(data.data));
                            if (location.href.indexOf("#") === -1) {
                                location.href = location.href + "#";
                                location.reload();
                            }
                        } else {

                        }
                    },
                    error: function () {
                        alert("发送失败");
                    }
                });
            }
        });

    </script>
</head>
<body>
<jsp:include page="user_bar.jsp"/>
<input id="PageContext" type="hidden" value="${pageContext.request.contextPath}"/>
<div id="main_page">
    <div class="content">
        <!--
        <div class="top">
            <input class="toggleAll" type="checkbox"/> 全选
        </div>
        <ul>
            <li>
                <div class="status">
                    <input type="checkbox"/>
                </div>
                <div class="show">
                    <img src="img/img1.jpeg" alt=""/>
                </div>
                <div class="title">标题标题</div>
                <div class="price">单价￥ 100.00</div>
                <div class="number">
                    <button>-</button>
                    <input type="text" value="1"/>
                    <button>+</button>
                </div>
                <div class="sub">总价￥ 100.00</div>
                <div class="destory">
                    <button>删除</button>
                </div>
            </li>
        </ul>
        <div class="bottom">
            <div class="totalNum">总件数 : 3</div>
            <div class="btns">
                <button class="clear">清空购物车</button>
                <button class="buy">去结算</button>
                <button class="removeComplete">删除所有已选中</button>
            </div>
            <div class="totalPrice">总价格 : ￥ <span>100.00</span></div>
        </div>
        -->
    </div>
</div>
</body>
<script type="text/javascript" src="js/cart.js"></script>
</html>
